﻿#include "widget_magnetic.h"
#include "ui_widget_magnetic.h"

#include <QtWidgets>

#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif



widgetMagnetic::widgetMagnetic(QWidget* parent)
	: QWidget(parent)
	, ui(new Ui::widgetMagnetic)
{
	ui->setupUi(this);

	setStyleSheet("border-color: black;");;

	// ui->widget->setPolar(true);

	ui->widget->plotLayout()->clear();
	QCPPolarAxisAngular* angularAxis = new QCPPolarAxisAngular(ui->widget);
	ui->widget->plotLayout()->addElement(0, 0, angularAxis);
	ui->widget->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
	angularAxis->setRangeDrag(false);
	angularAxis->setTickLabelMode(QCPPolarAxisAngular::lmUpright);
	angularAxis->radialAxis()->setTickLabelRotation(0);
	angularAxis->radialAxis()->setAngle(45);

	angularAxis->grid()->setAngularPen(QPen(QColor(200, 200, 200), 0, Qt::SolidLine));
	angularAxis->grid()->setSubGridType(QCPPolarGrid::gtAll);

	QCPPolarGraph* g1 = new QCPPolarGraph(angularAxis, angularAxis->radialAxis());
	QCPPolarGraph* g2 = new QCPPolarGraph(angularAxis, angularAxis->radialAxis());
	g2->setPen(QPen(QColor(255, 150, 20)));
	g2->setBrush(QColor(255, 150, 20, 50));
	g1->setScatterStyle(QCPScatterStyle::ssStar);
	g1->setPen(QPen(Qt::blue));
	//    g1->setLineStyle(QCPPolarGraph::lsNone);
	for (int i = 0; i < 100; i++) {
		g1->addData(i / 100.0 * 360.0, qSin(i / 100.0 * M_PI * 8) * 8 + 1);
		g2->addData(i / 100.0 * 360.0, qSin(i / 100.0 * M_PI * 6) * 2);
	}

	angularAxis->setRange(0, 360);
	angularAxis->radialAxis()->setRange(-10, 10);
}

widgetMagnetic::~widgetMagnetic()
{
	delete ui;
}
